package com.lottery.im.module.chat.presenter;

import android.app.Activity;
import com.lottery.im.MyApplication;
import com.lottery.im.api.ApiClient;
import com.lottery.im.api.observer.ShowTipObserver;
import com.lottery.im.api.result.entity.GiveRedPackets;
import com.lottery.im.base.BaseActivityPresenter;
import com.lottery.im.module.chat.view.SendSingleRedPacketsView;
import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.android.ActivityEvent;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import java.util.concurrent.TimeUnit;

public class SendSingleRedPacketsPresenter extends BaseActivityPresenter<SendSingleRedPacketsView> {

  public SendSingleRedPacketsPresenter(Activity activity,
      SendSingleRedPacketsView iView,
      LifecycleProvider<ActivityEvent> provider) {
    super(activity, iView, provider);
  }

  /**
   * 发送单个红包
   *
   * @param id 接受人ID
   * @param money 金额
   * @param note 备注
   * @param pwd 资金密码
   */
  public void giveSingleRedPackets(String id, String money, String note, String pwd) {
    ApiClient.getApiRetrofitInstance()
        .giveSingleRedPackets(MyApplication.getInstance().getUserInfo().getUserId(),
            MyApplication.getInstance().getToken(), id, money, note, pwd)
        .throttleFirst(2, TimeUnit.SECONDS)
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(new ShowTipObserver<GiveRedPackets>(activity) {
          @Override public void onSuccess(GiveRedPackets redPackets) {
            iView.giveSuc(redPackets);
          }
        });
  }

  /**
   * 发送群聊红包
   *
   * @param id 群ID
   * @param redPacketsType 红包类型
   * @param totalMoney 总金额
   * @param singleMoney 单个金额
   * @param totalNumber 总个数
   * @param note 备注
   * @param pwd 资金密码
   */
  public void giveRedPackets(String id, int redPacketsType, String totalMoney, String singleMoney,
      String totalNumber,
      String note, String pwd) {
    ApiClient.getApiRetrofitInstance()
        .giveRedPackets(MyApplication.getInstance().getUserInfo().getUserId(),
            MyApplication.getInstance().getToken(), id, redPacketsType, totalMoney, singleMoney,
            totalNumber, note, pwd)
        .throttleFirst(2, TimeUnit.SECONDS)
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(new ShowTipObserver<GiveRedPackets>(activity) {
          @Override public void onSuccess(GiveRedPackets redPackets) {
            iView.giveSuc(redPackets);
          }
        });
  }
}
